import { DeliverLogVO } from '@/services/DeliverLogService'
import { proxy } from '@@/exports'
import dayjs from 'dayjs'

interface DeliverLogModelType {
  deliverLog?: DeliverLogVO
  updateModalState: boolean
}

const state = proxy<DeliverLogModelType>({
  deliverLog: undefined,
  updateModalState: false,
})

const actions = {
  /**
   * 设置修改模态框状态
   * @param modalState 状态
   */
  setUpdateModalState(modalState: boolean) {
    state.updateModalState = modalState
  },
  /**
   * 打开模态框
   * @param modalState
   * @param deliverLog
   */
  openUpdateModal(modalState: boolean, deliverLog?: DeliverLogVO) {
    let bo: DeliverLogVO
    if (deliverLog) {
      bo = JSON.parse(JSON.stringify(deliverLog))
      bo.fee = bo?.fee / 100
      console.log('+++++++++++')
    } else {
      console.log('~~~~~~~~~~~~')
      bo = {
        deliverTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
      }
    }
    state.deliverLog = bo
    state.updateModalState = modalState
  },
}

export const DeliverLogModel = { state, actions }
